home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / gfx / show / swfplayersrc.lha / Player / timer.c < prev    next >
C/C++ Source or Header  |  2002-11-05  |  2KB  |  83 lines

  1. /*
  2. **
  3. ** $VER: timer.c 0.6 (05.11.02)
  4. **
  5. ** Description
  6. **        Timer utility fonctions
  7. **
  8. ** (C) Copyright 1999 Paul Hill
  9. ** (C) Copyright 2002 Alexandre Balaban
  10. **
  11. ** $HISTORY :
  12. **        - 0.6, 05.11.02 : Added pack pragma directives dor PPC compilation
  13. **        - 0.5, 04.11.02 : Improved PPC includes
  14. **        - 0.4, 03.10.02 : Include PPC compilation improvements by Steffen Haeuser
  15. **        - 0.3, 29.08.02 : Add WaitIO() in closetimer
  16. **        - 0.2, 25.07.02 : Cleanning by Alex
  17. **        - 0.1, 27.02.99 : Initial version by Paul Hill
  18. */
  19.  
  20. #pragma pack(2)
  21.  
  22. // [SHA, 03/10/2002 : PPC compilation improvement]
  23. #ifdef __PPC__
  24. #include </ADE/os-includeppc/proto/exec.h>
  25. #include </ADE/os-includeppc/proto/timer.h>
  26. #include <clib/alib_protos.h>
  27. #else
  28. #include <proto/exec.h>
  29. #include <proto/timer.h>
  30. #include <proto/alib.h>
  31. #endif // __PPC__
  32. // [END SHA, 03/10/2002]
  33.  
  34. #include <devices/timer.h>
  35. #include <sys/time.h>
  36.  
  37. #pragma pack()
  38.  
  39. #include <stdio.h>
  40.  
  41. #include "timer.h"
  42.  
  43. struct timerequest *TimerIO=NULL;
  44. struct MsgPort *TimerMP=NULL;
  45.  
  46. int opentimer( void )
  47. {
  48.     int rc=0;
  49.  
  50.     if( ( TimerMP = CreatePort( 0, 0 ) ) )
  51.     {
  52.         if( ( TimerIO = (struct timerequest *) CreateExtIO(TimerMP,sizeof(struct timerequest) ) ) )
  53.         {
  54.             /* Open the device once */
  55.             if (!(OpenDevice( TIMERNAME, UNIT_VBLANK,(struct IORequest *) TimerIO, 0L)))
  56.             {
  57.                 rc = 1;
  58.             }
  59.         }
  60.     }
  61.     return rc;
  62. }
  63.  
  64.  
  65. void closetimer( void )
  66. {
  67.     if (TimerIO)
  68.     {
  69.         /* Delete any pending timer requests */
  70.         if (!(CheckIO((struct IORequest *)TimerIO))) AbortIO((struct IORequest *)TimerIO);
  71.  
  72.         WaitIO( (struct IORequest*) TimerIO );
  73.  
  74.         CloseDevice((struct IORequest *) TimerIO);
  75.         DeleteExtIO((struct IORequest *) TimerIO);
  76.     }
  77.  
  78.     if (TimerMP)
  79.     {
  80.         DeletePort(TimerMP);
  81.     }
  82. }
  83.